<template>
	<view>
		<!-- 未登录的头像和文字 -->
		<view class="info" v-if="userinfo==null" @click="gotologin">
			<view class="info-avatar">
				<img src="@/static/icon/index.png" alt="">
			</view>
			<view class="info-msg">
				<text>立即登录> </text>
			</view>
		</view>
		<!--已登录的头像和用户名 -->
		<view class="info" v-else @click="userMessage">
			<view class="info-avatar">
				<img :src="userinfo.avatarUrl">
			</view>
			<view class="info-msg">
				<view class="info-msg-name">
					<text>{{userinfo.nickname}}</text>
				</view>
				<view class="info-msg-detail">
					<text>{{userinfo.follows}}关注</text>
					<text class="info-msg-detail-fans">{{userinfo.followeds}}粉丝</text>
					<text>Lv.{{Grade}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "User-info",
		data() {
			return {
				Grade: 8,
				userinfo: uni.getStorageSync('UserData').profile, //获取本地缓存的数据
			};
		},
		methods: {
			//前往登录
			gotologin() {
				uni.reLaunch({
					url: "/components/Login/Login"
				});
			},
			//前往用户信息
			userMessage() {
				uni.navigateTo({
					url: '/pages/index/ChildCpn/userMessage'
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.info {
		// height: 150rpx;
		display: flex;
		flex-direction: column;
		margin: 40rpx 30rpx;
		background: #fff;
		border-radius: 25rpx;
		text-align: center;

		&-avatar {
			// transform: translateY(-65rpx) ;
			margin-top: -65rpx;

			img {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				border: 1px solid #e5e5e5;
			}
		}

		&-msg {
			display: flex;
			flex-direction: column;

			&-name {
				font-weight: bold;
				margin-bottom: 20rpx;
			}

			&-detail {
				margin-bottom: 30rpx;

				&-fans {
					padding: 0 30rpx;
					border-left: 1px solid #727272;
					border-right: 1px solid #727272;
				}

				text {
					padding-left: 18rpx;
					font-size: 30rpx;
					color: #727272;
					padding-right: 15rpx;
				}
			}
		}
	}
</style>
